﻿

using OpenCvSharp;

using System;
using System.Collections.Generic;

using Xc.DataAccess.CodeReader.Properties;
using Xc.DataAccess.Core;

namespace Xc.DataAccess.CodeReader.Models.Filters
{
    /// <summary>
    /// 绘制文字
    /// </summary>
    [Filter("绘制文字",FilterType.Draw)]
    public class DrawText : FilterBase
    {
        string text;
        /// <summary>
        /// 绘制的文字
        /// </summary>
        [InputParameter("绘制的文字")]
        public string Text
        {
            get => text;
            set
            {
                if (text == value)
                {
                    return;
                }

                text = value;
                RaisedPropertyChanged();
            }
        }
        CVPoint startPoint;
        /// <summary>
        /// 起始点
        /// </summary>
        [InputParameter("起始点")]
        public CVPoint StartPoint
        {
            get => startPoint;
            set
            {
                if (startPoint == value)
                {
                    return;
                }

                startPoint = value;
                RaisedPropertyChanged();
            }
        }
        HersheyFonts fonts;
        /// <summary>
        /// 字体
        /// </summary>
        [InputParameter("字体")]
        public HersheyFonts Fonts
        {
            get => fonts;
            set
            {
                if (fonts == value)
                {
                    return;
                }

                fonts = value;
                RaisedPropertyChanged();
            }
        }
        bool bottomLeftOrigin = false;
        /// <summary>
        /// 左下角是原点
        /// </summary>
        [InputParameter("文字翻转")]
        public bool BottomLeftOrigin
        {
            get => bottomLeftOrigin;
            set
            {
                if (bottomLeftOrigin == value)
                {
                    return;
                }

                bottomLeftOrigin = value;
                RaisedPropertyChanged();
            }
        }
        LineTypes lineTypes;
        /// <summary>
        /// 线条类型
        /// </summary>
        [InputParameter("线条类型")]
        public LineTypes LineTypes
        {
            get => lineTypes;
            set
            {
                if (lineTypes == value)
                {
                    return;
                }

                lineTypes = value;
                RaisedPropertyChanged();
            }
        }
        Scalar color;
        /// <summary>
        /// 颜色
        /// </summary>
        [InputParameter("颜色")]
        public Scalar Color
        {
            get => color;
            set
            {
                if (color == value)
                {
                    return;
                }

                color = value;
                RaisedPropertyChanged();
            }
        }
        int fontScale = 1;
        /// <summary>
        /// 缩放大小
        /// </summary>
        [InputParameter("缩放大小")]
        public int FontScale
        {
            get => fontScale;
            set
            {
                if (fontScale == value)
                {
                    return;
                }

                fontScale = value;
                RaisedPropertyChanged();
            }
        }
        internal override ResultData<Mat> UseChannel(Mat mat,FilterBase[] filterBases, FilterBase preFilterBase)
        {
            if (string.IsNullOrEmpty(Text))
            {
                return ResultData<Mat>.Accept(TextResource.drawing_text_failed, mat);
            }
            Cv2.PutText(mat, Text, StartPoint, Fonts, FontScale, Color, FontScale, LineTypes, BottomLeftOrigin);
            return ResultData<Mat>.Accept(TextResource.drawing_text_success, mat);
        }
    }

}
